package cate.game.play.proce.move;

import cate.game.attr.FightAttr;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.turn.TurnCtx;
import cate.game.play.skill.Skill;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "追加的行动参数",detail = "在一个turn中的追加move")
public class AppendMove {

	@NoteField("追加行动者")
	public Fighter actor;

	@NoteField("追加的技能")
	public Skill skill;

	@NoteField("血量调整比例")
	public double hpChangeRate;

	@NoteField("本次move中的临时属性")
	public FightAttr moveAttr;

	@NoteField("追加行为来源的handler")
	public AppendMoveHandler handler;

	public AppendMove(Fighter actor, Skill skill) {
		this.actor = actor;
		this.skill = skill;
	}

	public AppendMove(Fighter actor, Skill skill, AppendMoveHandler handler) {
		this.actor = actor;
		this.skill = skill;
		this.handler = handler;
	}

	public void beforeAppendMove(TurnCtx turn) {
		if (moveAttr != null) {
			actor.attr.addMoveAttr(moveAttr, true);
		}
		if (handler != null) {
			handler.beforeAppendMove(turn, this);
		}
	}

	public void afterAppendMove(TurnCtx turn) {
		if (handler != null) {
			handler.afterAppendMove(turn, this);
		}
	}

	public void onAppendMoveFail(TurnCtx turn) {
		if (skill != null) {
			skill.reset();
		}
		if (handler != null) {
			handler.onAppendMoveFail(turn, this);
		}
	}

	/**
	 * 当前这个追加行动是否失效
	 * @return
	 */
	public boolean inValid(TurnCtx turn) {
		if (!actor.allowUseSkill(skill)) {
			return true;
		}
		if (!actor.buff.allowAppendMove(skill)) {
			return true;
		}
		if (handler != null && handler.inValid(turn, this)) {
			return true;
		}
		return false;
	}
}
